<?php
/**
 * Created by PhpStorm.
 * User: QK
 * Date: 2018-07-25
 * Time: 下午 3:18
 */
namespace app\blog\controller;
use app\blog\model\GoodspecModel as go;
use cmf\controller\AdminBaseController;
class GoodspecController extends AdminBaseController{
    /**
     * 商品规格列表
     */
    public function _initialize()
    {
        parent::_initialize();
        $this->go=new go();
    }

    public function index(){
        $param = $this->request->param('f_name');
        $session=$this->go->session();
        //获取规格
        $rest    = $this->go->goodspeclist($param);
        $this->assign('users',$rest['data']);
        $this->assign('page',$rest['page']);
        return $this->fetch('goodspec/goodslist');
    }
    /**
     * 添加商品规格页面
     */
    public function add(){
        $shop=$this->go->session();
        $this->assign('shop',$shop);
        return $this->fetch('goodsadd');

    }
    /**
     * 添加规格操作
     */
    public function addpost(){
        $date       = $this->request->param();
        $rest       = $this->go->goodspecadd($date);
        if($rest != false){
            $this->success('操作成功！','goodspec/index');
        }else{
            $this->error('操作失败！');
        }

    }
    /**
     * 修改规格页面
     */
    public function detail(){
        //获取指定规格
        $array=$this->request->param();
        $where['for_guid']=$array['for_guid'];
        $rest      = $this->go->getgone($where);
        $this->assign('rest',$rest);
        return $this->fetch();
    }
    /**
     * 修改规格操作
     */
    public function detailpost(){
        $date     = $this->request->param();
        $where['for_guid'] = $date['for_guid'];
        $data['f_name']=$date['name'];
        $rst      = $this->go->goodspecupdate($where,$data);
        if($rst != false){
            $this->success('修改成功！','Goodspec/index');
        }else{
            $this->error('修改失败');
        }
    }
    /**
     * 删除规格
     */
    public function del(){
        $date     = $this->request->param();
        $where['for_guid']       =$date['for_guid'];
        $rst      = $this->go->goodspecdelete($where);
        if($rst['num'] != false){
            $this->success($rst['con']);
        }else{
            $this->error($rst['con']);
        }
    }
    /*禁用启用功能*/
    public function upstatus(){
        $date        = $this->request->param();
        $where       = array();
        $where['for_guid'] = $date['for_guid'];
        $data['status']=$date['status'];
        $rest        = $this->go->goodspecupdate($where,$data);
        if($rest != false){
            $this->success("操作成功！");
        }else{
            $this->error('操作失败');
        }
    }
}